import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * 动态表单配置头
 * @date 2019-07-15
 */
import request from 'utils/request';
import { parseParameters, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
var tenantId = getCurrentOrganizationId();

function formHeaders() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/form-headers") : 'form-headers';
}
/**
 * 分页查询动态表单配置头
 * @param params
 * @returns {Promise<void>}
 */


export function fetchHeaderList() {
  return _fetchHeaderList.apply(this, arguments);
}
/**
 * 动态表单配置头明细
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _fetchHeaderList() {
  _fetchHeaderList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var params,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formHeaders()), {
              method: 'GET',
              query: parseParameters(params)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchHeaderList.apply(this, arguments);
}

export function fetchHeaderById(_x) {
  return _fetchHeaderById.apply(this, arguments);
}
/**
 * 新增动态配表单置头
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _fetchHeaderById() {
  _fetchHeaderById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formHeaders(), "/").concat(params.formHeaderId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchHeaderById.apply(this, arguments);
}

export function createHeader(_x2) {
  return _createHeader.apply(this, arguments);
}
/**
 * 更新动态表单配置头
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _createHeader() {
  _createHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formHeaders()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createHeader.apply(this, arguments);
}

export function updateHeader(_x3) {
  return _updateHeader.apply(this, arguments);
}
/**
 * 删除动态表单配置头
 * @param {Object} params - 参数
 * @returns {Promise<void>}
 */

function _updateHeader() {
  _updateHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formHeaders()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateHeader.apply(this, arguments);
}

export function removeHeader(_x4) {
  return _removeHeader.apply(this, arguments);
} // 查询启用的表单配置头列表

function _removeHeader() {
  _removeHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formHeaders()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _removeHeader.apply(this, arguments);
}

export function fetchAbleHeaderList() {
  return _fetchAbleHeaderList.apply(this, arguments);
}

function _fetchAbleHeaderList() {
  _fetchAbleHeaderList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var params,
        _args6 = arguments;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            params = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(formHeaders(), "/list"), {
              method: 'GET',
              query: parseParameters(params)
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchAbleHeaderList.apply(this, arguments);
}